package org.datascooter.db.h2;

import org.datascooter.cache.ConnectionManager;
import org.datascooter.exception.DataScooterException;
import org.datascooter.impl.DataManager;
import org.datascooter.impl.DataSource;
import org.datascooter.impl.SnipManager;
import org.datascooter.inface.IDataManager;
import org.datascooter.utils.DSSettings;

/**
 * The fastest and simplest way to start datascooter for work with H2 in memory mode
 * 
 * @author user
 * 
 */
public class MemoManagerBuilder {

	public static IDataManager build() {
		return build("h2mem", true);
	}

	public static IDataManager build(String dsName, boolean isDefault) {
		try {
			H2Connector connector = new H2Connector(new DataSource(dsName, "jdbc:h2:mem:dbh2mem", "sa", "", isDefault));
			ConnectionManager.register(connector, DSSettings.getConnectionPoolSize(), DSSettings.getWaitConnectionTimeout());
			return new DataManager(new SnipManager(connector), new H2SnipBuilder());
		} catch (Exception e) {
			throw new DataScooterException(e);
		}
	}
}
